<template>
  <!--
    max的值是通过父组件传递，父组件通过api获取会存在延迟
    初始化子组件max为undefined，因此需要通过watch监听并设置max值
  -->
  <div class="mui-numbox" data-numbox-min='1' :data-numbox-max='max' style="height:25px; ">
    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
    <input id="test" class="mui-input-numbox" type="number" value="1" ref="numbox" @change="countChange" />
    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
  </div>
</template>

<script>
import mui from "../../lib/mui/js/mui.min.js";

export default {
  mounted() {
    mui('.mui-numbox').numbox();
  },
  methods: {
    countChange() {
      this.$emit('getCount', this.$refs.numbox.value);
    }
  },
  props: ["max"],
  watch: {
      'max':function (newVal) {
          mui('.mui-numbox').numbox().setOption('max', newVal);
      }
  }
};
</script>

<style scoped>

</style>
